<template>
  <van-popup v-model="showPicker" position="bottom">
    <VantDataTime
      v-bind="{...$props,...$attrs}"
      v-on="$listeners"
      v-model="syncValue"
      @confirm="onConfirm"
      @cancel="showPicker = false"
    />
  </van-popup>
</template>

<script>
import VantDataTime from '../VantDataTime'

export default {
  name: 'VantDataTimePopup',
  components: { VantDataTime },
  model: {
    prop: 'value',
    event: 'update:value'
  },
  props: {
    title: {
      type: String,
      default: '选择年月日'
    },
    value: {
      type: String,
      default: ''
    },
    format: {
      type: String,
      default: 'YYYY-MM-DD'
    },
    disabled: {
      type: Boolean,
      default: false
    },
    type: {
      type: String,
      default: 'date'
    }
  },
  data() {
    return {
      showPicker: false,
    }
  },
  computed:{
    syncValue:{
      get(){
        return this.value
      },
      set(val){
        this.$emit('update:value',val)
      }
    }
  },
  methods: {
    onConfirm(value) {
      this.$emit('confirm', value)
      this.showPicker = false
    },
    showPopup() {
      if (this.disabled) {
        return
      }
      this.showPicker = true
    },
    open() {
      this.showPopup()
    },
  }
}
</script>

<style scoped lang="scss">

</style>
